package com.tuo51.childcare.controller;


import com.google.common.collect.ImmutableMap;
import com.tuo51.childcare.domain.expertroom.ExpertHint;
import com.tuo51.childcare.domain.expertroom.ExpertRoom;
import com.tuo51.childcare.service.BizStoreItemService;
import com.tuo51.childcare.service.ExpertRoomService;
import com.tuo51.evaluate.domain.evaluatingV2.EvaluateV2Record;
import com.tuo51.core.domain.staffs.Staff;
import com.tuo51.evaluate.service.EvaluateV2ConclusionService;
import com.tuo51.evaluate.service.EvaluateV2Service;
import com.tuo51.foudation.model.MemVerificationCache;
import com.tuo51.foudation.model.StatusResponse;
import com.tuo51.foudation.utils.CopyUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * 新手指引
 */

@RequestMapping("/papi/expert")
@RestController
@Api(value = "/papi/expert", tags = "家长服务号 - 专家诊室")
public class PAPIExpertRoomController {

    @Autowired
    BizStoreItemService storeItemService;

    @Autowired
    MemVerificationCache cache;

    @Autowired
    EvaluateV2Service evaluateV2Service;

    @Autowired
    private EvaluateV2ConclusionService conclusionService;

    @Autowired
    ExpertRoomService expertRoomService;

    @RequestMapping(value = "/room", method = RequestMethod.GET)
    public StatusResponse expertRoom(HttpServletRequest req,
                                   HttpServletResponse resp,
                                   @RequestHeader(value = "ticket", required = false) String ticket,
                                   String roomId,
                                   String reportId) {

        EvaluateV2Record detail = evaluateV2Service.getEvaluateDetail(reportId);

        Map result = conclusionService.generateReportExtInfo(detail);

        result.putAll(CopyUtils.transBean2Map(detail));

        ExpertRoom room = expertRoomService.forReport(reportId);

        String advice = "跟" + room.getExpert() + "一起制定每天学习计划，让宝贝健康成长吧";

        Map ret = ImmutableMap.of("room", room, "report", result, "planAdvice", advice);


        return StatusResponse.success(ret);
    }

    @RequestMapping(value = "/readhint", method = RequestMethod.GET)
    public StatusResponse readHint(HttpServletRequest req,
                                       HttpServletResponse resp,
                                       @RequestHeader(value = "ticket", required = false) String ticket,
                                       String hintId) {

        return StatusResponse.success();
    }

    @RequestMapping(value = "/hint", method = RequestMethod.GET)
    public StatusResponse hint(HttpServletRequest req,
                                       HttpServletResponse resp,
                                       @RequestHeader(value = "ticket", required = false) String ticket) {

        Staff staff = cache.getStaff(ticket);
        ExpertHint hint = expertRoomService.generateHintByReport(staff, null);

        return StatusResponse.success(hint);
    }
}
